<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
        
        <title>Add Unique To Array Documentation</title>
        
        <script src="/js/greyspots.js" type="text/javascript"></script>
        <link href="/css/greyspots.css" type="text/css" rel="stylesheet" />
        
        <script src="/js/ace/ace.js" data-ace-base="/js/ace/" type="text/javascript" charset="utf-8"></script>
        <script src="/js/ace/ext-language_tools.js" type="text/javascript"></script>
        <script src="/js/ace/ext-searchbox.js" type="text/javascript"></script>
        
        <script src="doc-library/doc.js" type="text/javascript"></script>
        <link href="doc-library/doc.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
        <gs-jumbo>
            <h1 class="text-center">Add Unique To Array</h1>
        </gs-jumbo>
            
        <gs-container min-width="sml;med;lrg">
            <h3>Function:</h3>
            <pre><code>GS.listAdd(&lt;ARRAY&gt;, &lt;VALUE-TO-ADD-IF-UNIQUE&gt;);</code></pre>
            
            <h3>Description:</h3>
            <p>This function is for adding values to an array if the value you want to add isn't already in the array. To add a value even if it is not unique you would use the Array Prototype .push() Function (documentation: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/push" target="_blank">MDN</a>, <a href="http://www.w3schools.com/jsref/jsref_push.asp" target="_blank">W3Schools</a>).</p>
            
            <b class="doc-header">Examples:</b>
            <div class="doc-example-description">
                <span class="h3">GS.listAdd Example:</span><br />
                <p>In this example when you click the "Add Value To Array If Unique" button the gs.listAdd function will add the text of the "text-new-value" control if that text is not already in the array and then the text of the array will be put into the "result" div so that you can see what happened. When you click the "Add Value To Array" the .push function will add the value to the array regardless of whether or not the value already exists in the array.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="10">
                    <gs-text id="text-new-value" value="test3"></gs-text>
                    <br />
                    <gs-button onclick="testListAdd()">Add Value To Array If Unique</gs-button>
                    <gs-button onclick="testPush()">Add Value To Array</gs-button>
                    <br />
                    <div id="result"></div>
                </template>
                <template for="js" height="24">
                    var arrTest = ['test1', 'test2'];
                    
                    function testListAdd() {
                        GS.listAdd(arrTest, document.getElementById('text-new-value').value);
                        
                        document.getElementById('result').textContent =
                            arrTest.toString();
                    }
                    
                    function testPush() {
                        arrTest.push(document.getElementById('text-new-value').value);
                        
                        document.getElementById('result').textContent =
                            arrTest.toString();
                    }
                </template>
            </gs-doc-example>
        </gs-container>
    </body>
</html>